package com.tianqu.tms.www.finance.controller;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.Attn;
import com.tianqu.tms.www.finance.actionform.BalanceSummaryForm;
import com.tianqu.tms.www.finance.viewhelper.BalanceSummaryViewHelper;

public class BalanceSummaryController  extends TmsController {
	private Logger logger = Logger.getLogger(BalanceSummaryController.class);

	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();
		try {
			//
			BalanceSummaryForm inputForm = (BalanceSummaryForm)uc.getInputForm();
			Attn attn = Attn.getInstance().finAttnList(inputForm.getMemberId());
			controller.commit();
			//
			BalanceSummaryViewHelper view = new BalanceSummaryViewHelper();
			view.setAction(inputForm.getAction());
			view.setMemberId(inputForm.getMemberId());
			view.setCount(attn.getCount());
			view.setTotalDailyRemain(attn.getTotalDailyRemain());
			view.setSumDailyRemain(attn.getSumDailyRemain());
			view.setInfo(attn.getInfo());
			view.setCurrentDate(attn.getCurrentDate());
			//
			uc.setAttribute(TmsConstants.VIEWHELP, view);
		} catch (Exception e) {
			logger.error(e);
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}
		logger.debug(this.getClass().getName() + "#execute was completed.");
	}
}
